namespace SimpleWebServices.Web.Mvc
{
    using System;
    using System.Web;
    using Moq;
    using SimpleWebServices;
    using SimpleWebServices.Configuration;
    using SimpleWebServices.Data;
    using SimpleWebServices.Models;
    using Xunit;

    public sealed class TenantUnauthorizedViewResultFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<TenantUnauthorizedViewResult>()
                .DerivesFrom<UnauthorizedViewResult>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Default.Clear();
            FakeRepository.Clear();

            try
            {
                Default.Register<Unauthorized>("<resource />");

                FakeRepository.Register<Tenant>(new
                {
                    urn = "urn://example.com/tenant/sample",
                    xml = 
                        "<tenant>" +
                            "<master-pages>" +
                                "<value name='html'>HtmlRepresentation.Default</value>" +
                            "</master-pages>" +
                        "</tenant>"
                });

                var mock = new Mock<HttpContextBase>();
                mock.SetupGet<string>(x => x.Request.Path).Returns("/sample").Verifiable();
                mock.SetupGet<Uri>(x => x.Request.Url).Returns(new Uri("http://www.example.com/sample")).Verifiable();
                HttpContextFactory.Mock = mock.Object;

                Assert.Equal<string>("HtmlRepresentation.Default", new TenantUnauthorizedViewResult().MasterName);
            }
            finally
            {
                Default.Reset();
                FakeRepository.Reset();
                HttpContextFactory.Reset();
            }
        }
    }
}